import type { TableData } from '@arco-design/web-vue/es/table/interface';
import http from '@/utils/http'
/**
 * 查询请求体
 */
export interface RoleQueryRequest {
  name?: string;
}
export interface RolePageQueryRequest extends RoleQueryRequest, PageQuery {}

/**
 * 角色查询响应
 */
export interface RoleQueryResponse extends TableData {
  id: number;
  name: string;
  code: string;
  status: number;
  note: string;
  sort: number;
  create_time?: number;
  update_time?: number;
  mark?: number;
}

/**
 * 角色更新请求
 */
export interface UpdateRequest {
  id?: number;
  status?: number;
  sort?: number;
  name?: string;
  code?: string;
  note?: string;
}

/**
 * 角色授权
 */
export interface UpdateAuthRequest {
  role_id?: number;
  menu_id?: Array<any>;
}

/**
 * 查询列表(不分页)
 */
export function getAllRole() {
  return http.get<RoleQueryResponse>('/admin/role/getRoleList');
}

/**
 * 查询列表(分页)
 */
export function getList(params: RolePageQueryRequest)  {
  return http.get<PageRes<RoleQueryResponse[]>>('/admin/role/index', params)
}

/**
 * 修改状态
 */
export function updateRowStatus(request: UpdateRequest) {
  return http.post('/admin/role/status', request);
}

/**
 * 通过id数组批量删除数据
 */
export function batchDeleteRows(idList: Array<number>) {
  return http.post('/admin/role/delete', {
    id: idList,
  });
}

/**
 * 通过 id 删除数据
 */
export function deleteRows(id: number) {
  return http.post('/admin/role/delete', { id })
}

/**
 * 通过 id 新增更新数据
 */
export function updateRows(request: UpdateRequest) {
  return http.put('/admin/role/edit', request);
}

export function getRoleMenus(id: number) {
  return http.post('/admin/role/getPermissionList', { role_id: id });
}

/**
 * 通过 id 授权角色
 */
export function authRows(request: UpdateAuthRequest) {
  return http.put('/admin/role/savePermission', request);
}
